import 'package:flutter/material.dart';

class ColorsUtils {
  ColorsUtils._();

  static const String colorB2b = '#B2B2B2';

  static const String colorFffFb2 = '#ffffffb2';

  static const String colorWhite = '#FFFFFF';

  static const String color333 = '#333333';

  static const String color363 = '#363636';

  static const String color797 = '#797979';

  static const String colorCc0 = '#CC0000';

  static const String colorFf6 = '#FF6E53';

  static const String colorFaf = '#FAF5F5';

  static const String color515 = '#515151';

  static const String color006 = '#0066CC';

  static const String colorCcc = '#CCCCCC';

  static const String color999 = '#999999';

  static const String colorFf68 = '#FF684D';

  static const String color000 = '#000000';

  static const String color666 = '#666666';

  static const String colorE7e = '#e7e7e7';

  static const String color5e5 = '#5E5E5E';

  static const String colorFa5 = '#FA5151';

  static const String colorFeb = '#FEBDB4';

  static const String colorA1a = '#A1A1A1';

  static const String colorFf0 = '#FF0000';

  static const String colorFb8 = '#FB8974';

  static Color fromRGBO([int r = 255, int g = 255, int b = 255, double opacity = 1.0]) {
    return Color.fromRGBO(r, g, b, opacity);
  }

  static Color rgba([int r = 255, int g = 255, int b = 255, double opacity = 1.0]) {
    return fromRGBO(r, g, b, opacity);
  }

  static Color parseColorFromHexString(String code) {
    Color result = Colors.red;
    int value = 0;
    if (code.contains('#')) {
      try {
        value = int.parse(code.substring(1), radix: 16);
      } catch (e) {
        debugPrint(e.toString());
      }
      switch (code.length) {
        case const (1 + 6):

          ///6位
          result = Color(value + 0xFF000000);
          break;
        case const (1 + 8):

          ///8位
          result = Color(value);
          break;
        default:
          result = Colors.red;
      }
    } else {
      try {
        value = int.parse(code, radix: 16);
      } catch (e) {
        print(e);
      }
      switch (code.length) {
        case 6:
          result = Color(value + 0xFF000000);
          break;
        case 8:
          result = Color(value);
          break;
        default:
          result = Colors.red;
      }
    }
    return result;
  }

  static Color colorFromHexString(String? s) {
    return parseColorFromHexString(s ?? colorWhite);
  }

  static Color whiteColor() {
    return parseColorFromHexString(colorWhite);
  }
}
